----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 10912 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Channel Light"
SPELL.m_sToolTip =	[[You channel the light around you, 
					healing allies and damaging enemies
					in a small radius.]]
SPELL.m_sIcon = "devin/blackbetty/spells/mage/manatap.png"
SPELL.m_iCoolDown = 10
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = false
SPELL.m_iSpellType = SPELLTYPE_RANGEDAMAGE

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	
	print("Casted "..self.m_sName.."!")
	
	local range = self.m_iRange
		
	ParticleEffectAttach("light_hands", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
	ParticleEffectAttach("light_hands", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_LH"))
	pl:EmitSound("devin/blackbetty/weapons/saiyan.wav", 60, math.random(100, 105))
	self.CastSound = CreateSound( pl, "devin/blackbetty/weapons/travelsounds/HolyMissileLoop.wav" )
	self.CastSound:ChangePitch( 80, 0 )
	self.CastSound:Play()
	timer.Simple(5, function()
		self.CastSound:Stop()
		pl:StopParticles()
	end)
	timer.Create(""..pl:EntIndex().."channelres", 1, 5, function()
		UpdatePlayerResource(pl, 1, true)
	end)
	timer.Create(""..pl:EntIndex().."channelparticles", 0.1, 50, function()
		ParticleEffect( "impact_light_damage", pl:GetPos(), Angle(0,0,0), pl )
	end)
	timer.Create(""..pl:EntIndex().."channel", 0.5, 10, function()
		self:DealDamage(-4, -4, pl, pl, DMG_GENERIC)
		local whirlRadius = ents.FindInSphere(pl:GetPos(), 240)
		for i, s in ipairs(whirlRadius)do
			if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm")then
				self:Effect(pl, s)
			end
		end
	end)
end

function SPELL:Effect(pl, target)
	if(target:EntIndex() != pl:EntIndex())then
		if(target:IsPlayer() && target:Team() == pl:Team())then
			self:DealDamage(-4, -4, pl, target, DMG_GENERIC)
		else
			self:DealDamage(8, 8, pl, target, DMG_GENERIC)
		end
		ParticleEffect( "impact_light_damage", target:GetPos(), Angle(0,0,0), pl )
		target:EmitSound("devin/blackbetty/weapons/castsounds/HolyCast.wav", 100, 100)
	end
end






